package com.wat.aop.example2;

import org.springframework.aop.target.HotSwappableTargetSource;
import org.springframework.cglib.proxy.Proxy;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AopExample2Main {
	public static void main(String[] args) {
		//		BeanFactory context = new XmlBeanFactory(new ClassPathResource("AopTest.xml"));
		ClassPathXmlApplicationContext context =
				new ClassPathXmlApplicationContext("${wat:classpath:AopTest.xml}");
		Object aopWorker = context.getBean("aopWorker");
		Object aopCapitalist = context.getBean("aopCapitalist");

		assert !(aopCapitalist instanceof Proxy);
		assert aopWorker instanceof Proxy;

//		Capitalist capitalist = (Capitalist) aopCapitalist;
//		capitalist.work();
		System.out.println("\n普通的打工人：");
		Worker worker = (Worker) aopWorker;
		worker.work();

		System.out.println("\n难过的打工人：");
		SadWorker sadWorker = new SadWorker();
		HotSwappableTargetSource targetSource = context.getBean("hotSwappableTargetSource", HotSwappableTargetSource.class);
		targetSource.swap(sadWorker);
		worker.work();
	}
}
